package www.openteam.com.rewrite;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;



/**
 * Created by OT on 2017-08-23.
 */

public class MTextView extends android.support.v7.widget.AppCompatTextView {

    public MTextView(Context context) {
        super(context);
    }

    public MTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

//    @Override
//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//
//
//        Layout layout = getLayout();
//        if (layout != null) {
//            int height = (int) Math.ceil(getMaxLineHeight(this.getText().toString()))
//                    + getCompoundPaddingTop() + getCompoundPaddingBottom();
//            int width = getMeasuredWidth();
//            setMeasuredDimension(width, height);
//        }
//    }
//
//
//    private float getMaxLineHeight(String str) {
//        float height = 0.0f;
//        float screenW = getActivityFromView(this).getWindowManager().getDefaultDisplay().getWidth();
//        float paddingLeft = ((GridLayout) this.getParent()).getPaddingLeft();
//        float paddingReft = ((GridLayout) this.getParent()).getPaddingRight();
//        //这里具体this.getPaint()要注意使用，要看你的TextView在什么位置，这个是拿TextView父控件的Padding的，为了更准确的算出换行
//        int line = (int) Math.ceil((this.getPaint().measureText(str) / (screenW - paddingLeft - paddingReft)));
//        height = (this.getPaint().getFontMetrics().descent - this.getPaint().getFontMetrics().ascent) * line;
//        return height;
//    }
//    public static Activity getActivityFromView(View view) {
//        Context context = view.getContext();
//        while (context instanceof ContextWrapper) {
//            if (context instanceof Activity) {
//                return (Activity) context;
//            }
//            context = ((ContextWrapper) context).getBaseContext();
//        }
//        return null;
//    }


    @Override
    public boolean isFocused() {
        return true;
    }
}
